<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0"><title>学习--ElasticSearch | Celts</title><meta name="author" content="PaulGeorge"><meta name="copyright" content="PaulGeorge"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="每天一篇面小水文，记录一下学习历程  本篇着重介绍一下 ElasticSearch      写在前面 好久没有跟新博客了，话不多说，开始学习 elastic search ! You Know, for Search">
<meta property="og:type" content="article">
<meta property="og:title" content="学习--ElasticSearch">
<meta property="og:url" content="https://curry3035.gitee.io/posts/27951/index.html">
<meta property="og:site_name" content="Celts">
<meta property="og:description" content="每天一篇面小水文，记录一下学习历程  本篇着重介绍一下 ElasticSearch      写在前面 好久没有跟新博客了，话不多说，开始学习 elastic search ! You Know, for Search">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://curry3035.gitee.io/img/avatar.jpg">
<meta property="article:published_time" content="2021-09-29T01:00:00.000Z">
<meta property="article:modified_time" content="2022-05-26T18:19:03.431Z">
<meta property="article:author" content="PaulGeorge">
<meta property="article:tag" content="进阶">
<meta property="article:tag" content="es">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://curry3035.gitee.io/img/avatar.jpg"><link rel="shortcut icon" href="/img/ic.ico"><link rel="canonical" href="https://curry3035.gitee.io/posts/27951/index.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: {"path":"/search.xml","preload":false,"languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":false,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: true,
    post: true
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: {"limitCount":50,"languages":{"author":"作者: PaulGeorge","link":"链接: ","source":"来源: Celts","info":"著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。"}},
  lightbox: 'fancybox',
  Snackbar: {"chs_to_cht":"你已切换为繁体","cht_to_chs":"你已切换为简体","day_to_night":"你已切换为深色模式","night_to_day":"你已切换为浅色模式","bgLight":"#49b1f5","bgDark":"#1f1f1f","position":"top-right"},
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: false,
  }
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: '学习--ElasticSearch',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2022-05-27 02:19:03'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
    win.getCSS = (url,id = false) => new Promise((resolve, reject) => {
      const link = document.createElement('link')
      link.rel = 'stylesheet'
      link.href = url
      if (id) link.id = id
      link.onerror = reject
      link.onload = link.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        link.onload = link.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(link)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><link rel="stylesheet" href="/css/background.css"><link rel="stylesheet" href="/css/my.css"><meta name="generator" content="Hexo 5.4.2"></head><body><div id="web_bg"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="/img/avatar.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">97</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">64</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">25</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fa fa-archive"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fa fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fa fa-folder-open"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/photos/"><i class="fa-fw fa fa-camera-retro"></i><span> 图库</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://gcore.jsdelivr.net/gh/PaulGeorge123/cloudimg@img/mig2023/background05.jpg')"><nav id="nav"><span id="blog-info"><a href="/" title="Celts"><span class="site-name">Celts</span></a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search" href="javascript:void(0);"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fa fa-archive"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fa fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fa fa-folder-open"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/photos/"><i class="fa-fw fa fa-camera-retro"></i><span> 图库</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">学习--ElasticSearch</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2021-09-29T01:00:00.000Z" title="发表于 2021-09-29 09:00:00">2021-09-29</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2022-05-26T18:19:03.431Z" title="更新于 2022-05-27 02:19:03">2022-05-27</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E6%95%B0%E6%8D%AE%E5%BA%93/">数据库</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">2.8k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>9分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="学习--ElasticSearch"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><blockquote>
<p>每天一篇面小水文，记录一下学习历程</p>
</blockquote>
<p><strong>本篇着重介绍一下 ElasticSearch</strong></p>
<hr>
<img src="https://gcore.jsdelivr.net/gh/PaulGeorge123/cloudimg@master/img/all/elasticsearch-Logo.png" style="zoom: 30%;" />



<p><strong>写在前面</strong></p>
<p>好久没有跟新博客了，话不多说，开始学习 elastic search !</p>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line">You Know, <span class="keyword">for</span> Search</span><br></pre></td></tr></table></figure>



<span id="more"></span>



<h3 id="ElasticSearch-的基本概念"><a href="#ElasticSearch-的基本概念" class="headerlink" title="ElasticSearch 的基本概念"></a>ElasticSearch 的基本概念</h3><h4 id="概念包括"><a href="#概念包括" class="headerlink" title="概念包括"></a>概念包括</h4><p><strong><font color=#FF8C00>cluster, node, index, document, shards 及 replica</font></strong></p>
<h4 id="集群（cluster）"><a href="#集群（cluster）" class="headerlink" title="集群（cluster）"></a>集群（cluster）</h4><img src="https://gcore.jsdelivr.net/gh/PaulGeorge123/cloudimg@master/img/all/Snipaste_2021-10-01_23-05-41.png" style="zoom:67%;" />

<br/>

<p><strong>Cluster</strong> 也就是集群的意思。Elasticsearch 集群由一个或多个节点组成，可通过其集群名称进行标识。通常这个 Cluster 的名字是可以在 Elasticsearch 里的配置文件中设置的。在默认的情况下，Elasticsearch 已经开始运行，那么它会自动生成一个叫做 “elasticsearch” 的集群。我们可以在 config/elasticsearch.yml 里定制我们的集群的名字。</p>
<img src="https://gcore.jsdelivr.net/gh/PaulGeorge123/cloudimg@master/img/all/Snipaste_2021-10-01_22-51-16.png" style="zoom:50%;" />



<p>一个 Elasticsearch 的集群就像是下面的一个布局</p>
<img src="https://gcore.jsdelivr.net/gh/PaulGeorge123/cloudimg@master/img/all/Snipaste_2021-10-01_23-49-34.png" style="zoom: 67%;" />



<p>带有 NGINX 代理及 Balancer 的架构图</p>
<img src="https://gcore.jsdelivr.net/gh/PaulGeorge123/cloudimg@master/img/all/Snipaste_2021-10-01_23-47-05.png" style="zoom:67%;" />

<hr>
<h4 id="实例（node）"><a href="#实例（node）" class="headerlink" title="实例（node）"></a>实例（node）</h4><p>单个 Elasticsearch 实例。 在大多数环境中，每个节点都在单独的盒子或虚拟机上运行。一个集群由一个或多个 node 组成。在测试的环境中，我可以把多个 node 运行在一个 server 上。在实际的部署中，大多数情况还是需要一个 server 上运行一个 node。</p>
<p> 根据 node 的作用，可以分为如下的几种：</p>
<ul>
<li><p>master-eligible：可以作为主 node，一旦成为主 node，它可以管理整个 cluster 的设置及变化：创建，更新，删除 index；添加或删除 node；为 node 分配 shard</p>
</li>
<li><p>data：数据 node</p>
</li>
<li><p>ingest: 数据接入</p>
</li>
<li><p>machine learning </p>
</li>
</ul>
<table>
<thead>
<tr>
<th align="center">Node类型</th>
<th align="center">配置参数</th>
<th align="center">默认值</th>
</tr>
</thead>
<tbody><tr>
<td align="center">master-eligible</td>
<td align="center">node.master</td>
<td align="center">true</td>
</tr>
<tr>
<td align="center">data</td>
<td align="center">node.data</td>
<td align="center">true</td>
</tr>
<tr>
<td align="center">ingest</td>
<td align="center">node.ingest</td>
<td align="center">true</td>
</tr>
<tr>
<td align="center">machine learning</td>
<td align="center">node.ml</td>
<td align="center">true (除了OSS发布版）</td>
</tr>
</tbody></table>
<p>整个 Elastic 的架构中，Data Node 和 Cluster 的关系表</p>
<p><img src="https://gcore.jsdelivr.net/gh/PaulGeorge123/cloudimg@master/img/all/Snipaste_2021-10-01_23-59-59.png"></p>
<hr>
<h4 id="索引（index）"><a href="#索引（index）" class="headerlink" title="索引（index）"></a>索引（index）</h4><p>在 Elasticsearch 中，索引是文档的集合。</p>
<p>索引是 <strong>Elasticsearch</strong> 对逻辑数据的逻辑存储，所以它可以分为更小的部分。</p>
<p>可以把索引看成关系型数据库的表，索引的结构是为快速有效的全文索引准备的，特别是它不存储原始值。</p>
<p><strong>Elasticsearch</strong> 可以把索引存放在一台机器或者分散在多台服务器上，每个索引有一或多个分片（<strong>shard</strong>），每个分片可以有多个副本（<strong>replica</strong>）。</p>
<img src="https://gcore.jsdelivr.net/gh/PaulGeorge123/cloudimg@master/img/all/Snipaste_2021-10-02_00-15-59.png" style="zoom:67%;" />

<br/>

<p><font color=#FF8C00>每个 Index 一个或许多的 documents 组成，并且这些 document 可以分布于不同的 shard 之中</font></p>
<img src="https://gcore.jsdelivr.net/gh/PaulGeorge123/cloudimg@master/img/all/Snipaste_2021-10-02_00-24-58.png" style="zoom:67%;" />

<br/>

<p><strong>注意</strong></p>
<p>正向索引使用的是一种文档到关键字的方式 <code>document -&gt; to -&gt; words</code>，那如果将 文档到关键字的结构反过来呢？是不是 <code>word -&gt; to -&gt; documents</code>，称之为 反向索引，也称为倒排索引</p>
<hr>
<h4 id="文档（document）"><a href="#文档（document）" class="headerlink" title="文档（document）"></a>文档（document）</h4><p>Elasticsearch 是面向文档的，这意味着你索引或搜索的最小数据单元是文档。</p>
<ul>
<li>存储在 <strong>Elasticsearch</strong> 中的主要实体叫文档（<strong>document</strong>）。用关系型数据库来类比的话，一个文档相当于数据库表中的<strong>一行记录</strong>。</li>
<li><strong>Elasticsearch</strong> 和 <strong>MongoDB</strong> 中的文档类似，都可以有不同的结构，但 <strong>Elasticsearch</strong> 的文档中，相同字段必须有相同类型。</li>
<li>文档由多个字段组成，每个字段可能多次出现在一个文档里，这样的字段叫多值字段（<strong>multivalued</strong>）。 每个字段的类型，可以是文本、数值、日期等。字段类型也可以是复杂类型，一个字段包含其他子文档或者数组。</li>
<li>它是独立的。文档包含字段（名称）及其值。</li>
</ul>
<p><strong>注意</strong></p>
<p><font color=#FF8C00>文档通常是数据的 <strong>JSON</strong> 表示形式</font></p>
<p>例如：</p>
<figure class="highlight json"><table><tr><td class="code"><pre><span class="line"><span class="punctuation">&#123;</span></span><br><span class="line">  <span class="attr">&quot;name&quot;</span><span class="punctuation">:</span> <span class="string">&quot;Elasticsearch Denver&quot;</span><span class="punctuation">,</span></span><br><span class="line">  <span class="attr">&quot;organizer&quot;</span><span class="punctuation">:</span> <span class="string">&quot;Lee&quot;</span><span class="punctuation">,</span></span><br><span class="line">  <span class="attr">&quot;location&quot;</span><span class="punctuation">:</span> <span class="string">&quot;Denver, Colorado, USA&quot;</span></span><br><span class="line"><span class="punctuation">&#125;</span></span><br></pre></td></tr></table></figure>
<hr>
<h4 id="分片（shard）"><a href="#分片（shard）" class="headerlink" title="分片（shard）"></a>分片（shard）</h4><p>由于 Elasticsearch 是一个分布式搜索引擎，因此索引通常会拆分为分布在多个节点上的称为分片的元素。 Elasticsearch 自动管理这些分片的排列。</p>
<p>当索引过于庞大的时候（磁盘无法存储下），为了解决这个问题，Elasticsearch 提供了将索引划分成多份的能力，这些份就叫做分片（shard）。</p>
<p>当创建一个索引的时候，你可以指定你想要的分片(shard)的数量。每个分片本身也是一个功能完善并且独立的“索引”，这个“索引”可以被放置到集群中的任何节点上。<br>分片之所以重要，主要有两方面的原因：</p>
<ul>
<li>允许水平分割/扩展你的内容容量</li>
<li>允许在分片（潜在地，位于多个节点上）之上进行分布式的、并行的操作，进而提高性能/吞吐量</li>
</ul>
<p>有两种类型的分片：primary shard 和 replica shard</p>
<p><strong>Primary shard</strong>: 每个文档都存储在一个Primary shard</p>
<p><strong>Replica shard</strong>: 每个主分片可以具有零个或多个副本</p>
<img src="https://gcore.jsdelivr.net/gh/PaulGeorge123/cloudimg@master/img/all/Snipaste_2021-10-02_00-37-22.png" style="zoom:45%;" />

<br/>

<p>建议 <strong>50G</strong> 为索引的大小以求得最好的性能。在我们实际的 Beats 的使用中，默认的 ILM 索引大小就是 50G。</p>
<hr>
<h4 id="副本（replica）"><a href="#副本（replica）" class="headerlink" title="副本（replica）"></a>副本（replica）</h4><p>默认情况下，Elasticsearch 为每个索引创建一个主分片和一个副本。这意味着每个索引将包含一个主分片，每个分片将具有一个副本。</p>
<p><strong>shard</strong> 健康</p>
<ul>
<li><font color=#FF0000>红色</font>：集群中未分配至少一个主分片</li>
<li><font color=#FF8C00>黄色</font>：已分配所有主副本，但未分配至少一个副本</li>
<li><font color=#008000>绿色</font>：分配所有分片</li>
</ul>
<hr>
<h4 id="映射（mapping）"><a href="#映射（mapping）" class="headerlink" title="映射（mapping）"></a>映射（mapping）</h4><p>所有文档写进索引之前都会先进行分析，如何将输入的文本分割为词条、哪些词条又会被过滤，这种行为叫做 映射（<strong>mapping</strong>）。一般由用户自己定义规则。</p>
<p>每当一个文档进来后，根据文档的 id 会自动进行 hash 计算，并存放于计算出来的 shard 实例中，这样的结果可以使得所有的 shard 都比较有均衡的存储，而不至于有的 shard 很忙。</p>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">shard_num = <span class="built_in">hash</span>(_routing) % num_primary_shards</span><br></pre></td></tr></table></figure>



<hr>
<h4 id="文档类型（type）"><a href="#文档类型（type）" class="headerlink" title="文档类型（type）"></a>文档类型（type）</h4><ul>
<li>在 <strong>Elasticsearch</strong> 中，一个索引对象可以存储很多不同用途的对象。例如，一个博客应用程序可以保存文章和评论。</li>
<li>每个文档可以有不同的结构。</li>
<li>不同的文档类型不能为相同的属性设置不同的类型。例如，在同一索引中的所有文档类型中，一个叫 <strong>title</strong> 的字段必须具有相同的类型。</li>
</ul>
<p>Elasticsearch 的数据类型：</p>
<ul>
<li>text：全文搜索字符串</li>
<li>keyword：用于精确字符串匹配和聚合</li>
<li>date 及 date_nanos：格式化为日期或数字日期的字符串</li>
<li>byte, short, integer, long：整数类型</li>
<li>boolean：布尔类型</li>
<li>float，double，half_float：浮点数类型</li>
<li>分级的类型：object 及 nested</li>
</ul>
<p><strong>注意</strong></p>
<p>在未来的版本中，type 将被彻底删除</p>
<hr>
<h4 id="RESTful-API"><a href="#RESTful-API" class="headerlink" title="RESTful API"></a>RESTful API</h4><p>在 <strong>Elasticsearch</strong> 中，提供了功能丰富的 <strong>RESTful API</strong> 的操作，包括基本的 <strong>CRUD</strong>、创建索引、删除索引等操作。</p>
<hr>
<h4 id="数据格式"><a href="#数据格式" class="headerlink" title="数据格式"></a>数据格式</h4><p>Elasticsearch 是面向文档型数据库，一条数据在这里就是一个文档。以 Elasticsearch 里存储文档数据和关系型数据库 MySQL 存储数据的概念进行一个类比。</p>
<img src="https://gcore.jsdelivr.net/gh/PaulGeorge123/cloudimg@master/img/all/Snipaste_2021-09-29_01-43-20.png" style="zoom:80%;" />



<p>ES 里的 Index 可以看做一个库，而 Types 相当于表，Documents 则相当于表的行。 这里 Types 的概念已经被逐渐弱化，Elasticsearch 6.X 中，一个 index 下已经只能包含一个 type，Elasticsearch 7.X 中, Type 的概念已经被删除了。</p>
<br/>



<h3 id="ElasticSearch-操作"><a href="#ElasticSearch-操作" class="headerlink" title="ElasticSearch 操作"></a>ElasticSearch 操作</h3><h4 id="ElasticSearch-API"><a href="#ElasticSearch-API" class="headerlink" title="ElasticSearch API"></a><a target="_blank" rel="noopener" href="https://www.elastic.co/guide/en/elasticsearch/reference/current/docs.html">ElasticSearch API</a></h4><h4 id="查看所有索引"><a href="#查看所有索引" class="headerlink" title="查看所有索引"></a>查看所有索引</h4><p>在 Postman 中，向 ES 服务器发 GET 请求 ：<code>http://127.0.0.1:9200/_cat/indices?v</code></p>
<ul>
<li><code>_cat</code> 表示查看的意思</li>
<li><code>indices</code> 表示索引</li>
<li>{&thinsp;{&thinsp;es_url&thinsp;}&thinsp;} =&gt; <code>http://localhost:9200</code></li>
</ul>
<p><img src="https://gcore.jsdelivr.net/gh/PaulGeorge123/cloudimg@master/img/all/Snipaste_2021-09-29_01-55-16.png"></p>
<hr>
<table>
<thead>
<tr>
<th>表头</th>
<th>含义</th>
</tr>
</thead>
<tbody><tr>
<td>health</td>
<td>当前服务器健康状态： <font color=#008000>green</font> (集群完整)、<font color=#FF8C00>yellow</font> (单点正常、集群不完整)、<font color=#FF0000>red</font> (单点不正常)</td>
</tr>
<tr>
<td>status</td>
<td>索引打开、关闭状态</td>
</tr>
<tr>
<td>index</td>
<td>索引名</td>
</tr>
<tr>
<td>uuid</td>
<td>索引统一编号</td>
</tr>
<tr>
<td>pri</td>
<td>主分片数量</td>
</tr>
<tr>
<td>rep</td>
<td>副本数量</td>
</tr>
<tr>
<td>docs.count</td>
<td>可用文档数量</td>
</tr>
<tr>
<td>docs.deleted</td>
<td>文档删除状态（逻辑删除）</td>
</tr>
<tr>
<td>store.size</td>
<td>主分片和副分片整体占空间大小</td>
</tr>
<tr>
<td>pri.store.size</td>
<td>主分片占空间大小</td>
</tr>
</tbody></table>
<h4 id="创建一个索引及文档"><a href="#创建一个索引及文档" class="headerlink" title="创建一个索引及文档"></a>创建一个索引及文档</h4><p>创建一个叫做 <strong>twitter</strong> 的索引（index），并插入一个文档（document)。</p>
<blockquote>
<p>在 <code>kibana</code> 中，向 ES 服务器发 PUT 请求 </p>
</blockquote>
<figure class="highlight json"><table><tr><td class="code"><pre><span class="line">PUT twitter/_doc/<span class="number">1</span></span><br><span class="line"><span class="punctuation">&#123;</span></span><br><span class="line">  <span class="attr">&quot;user&quot;</span><span class="punctuation">:</span> <span class="string">&quot;GB&quot;</span><span class="punctuation">,</span></span><br><span class="line">  <span class="attr">&quot;uid&quot;</span><span class="punctuation">:</span> <span class="number">1</span><span class="punctuation">,</span></span><br><span class="line">  <span class="attr">&quot;city&quot;</span><span class="punctuation">:</span> <span class="string">&quot;Beijing&quot;</span><span class="punctuation">,</span></span><br><span class="line">  <span class="attr">&quot;province&quot;</span><span class="punctuation">:</span> <span class="string">&quot;Beijing&quot;</span><span class="punctuation">,</span></span><br><span class="line">  <span class="attr">&quot;country&quot;</span><span class="punctuation">:</span> <span class="string">&quot;China&quot;</span></span><br><span class="line"><span class="punctuation">&#125;</span></span><br></pre></td></tr></table></figure>



<h4 id="自动-ID-生成"><a href="#自动-ID-生成" class="headerlink" title="自动 ID 生成"></a>自动 ID 生成</h4><p>Elasticsearch 自动帮我们生成一个 ID，这个时候使用的是 <code>POST </code> 而不是 <code>PUT</code> </p>
<p>操作数据的时候PUT和POST的区别：</p>
<ol>
<li><p>更新：PUT 会将新的 json 值完全替换掉旧的；而 POST 方式只会更新相同字段的值，其他数据不会改变，新提交的字段若不存在则增加。</p>
</li>
<li><p>PUT 和 DELETE 操作是<strong>幂等</strong>的。</p>
<p>所谓幂等是指不管进行多少次操作，结果都一样。比如用PUT修改一篇文章，然后在做同样的操作，每次操作后的结果并没有什么不同，DELETE也是一样。</p>
</li>
<li><p>POST 操作不是幂等的，比如常见的 POST 重复加载问题：当我们多次发出同样的 POST 请求后，其结果是创建了若干的资源。</p>
</li>
<li><p>创建操作可以使用 POST，也可以使用 PUT，区别就在于 POST 是作用在一个集合资源(/articles)之上的，而 PUT 操作是作用在一个具体资源之上的(/articles/1)。</p>
</li>
</ol>
<h4 id="修改一个文档"><a href="#修改一个文档" class="headerlink" title="修改一个文档"></a>修改一个文档</h4><figure class="highlight json"><table><tr><td class="code"><pre><span class="line">POST /&lt;index&gt;/_update/&lt;_id&gt;</span><br></pre></td></tr></table></figure>

<p>使用 PUT 命令来对我们的 id 为1的文档进行修改</p>
<figure class="highlight json"><table><tr><td class="code"><pre><span class="line">PUT twitter/_doc/<span class="number">1</span></span><br><span class="line"><span class="punctuation">&#123;</span></span><br><span class="line">   <span class="attr">&quot;user&quot;</span><span class="punctuation">:</span> <span class="string">&quot;GB&quot;</span><span class="punctuation">,</span></span><br><span class="line">   <span class="attr">&quot;uid&quot;</span><span class="punctuation">:</span> <span class="number">1</span><span class="punctuation">,</span></span><br><span class="line">   <span class="attr">&quot;city&quot;</span><span class="punctuation">:</span> <span class="string">&quot;北京&quot;</span><span class="punctuation">,</span></span><br><span class="line">   <span class="attr">&quot;province&quot;</span><span class="punctuation">:</span> <span class="string">&quot;北京&quot;</span><span class="punctuation">,</span></span><br><span class="line">   <span class="attr">&quot;country&quot;</span><span class="punctuation">:</span> <span class="string">&quot;中国&quot;</span><span class="punctuation">,</span></span><br><span class="line">   <span class="attr">&quot;location&quot;</span><span class="punctuation">:</span><span class="punctuation">&#123;</span></span><br><span class="line">     <span class="attr">&quot;lat&quot;</span><span class="punctuation">:</span><span class="string">&quot;29.084661&quot;</span><span class="punctuation">,</span></span><br><span class="line">     <span class="attr">&quot;lon&quot;</span><span class="punctuation">:</span><span class="string">&quot;111.335210&quot;</span></span><br><span class="line">   <span class="punctuation">&#125;</span></span><br><span class="line"><span class="punctuation">&#125;</span></span><br></pre></td></tr></table></figure>



<p>GET 来进行查询</p>
<figure class="highlight json"><table><tr><td class="code"><pre><span class="line">GET twitter/_doc/<span class="number">1</span></span><br></pre></td></tr></table></figure>



<h4 id="UPSERT-一个文档"><a href="#UPSERT-一个文档" class="headerlink" title="UPSERT 一个文档"></a>UPSERT 一个文档</h4><p> <code>upsert</code> 宽松地表示更新或插入，即更新文档（如果存在），否则，插入新文档。</p>
<p><code>doc_as_upsert </code> 参数检查具有给定ID的文档是否已经存在，并将提供的 doc 与现有文档合并。</p>
<figure class="highlight json"><table><tr><td class="code"><pre><span class="line">POST /catalog/_update/<span class="number">3</span></span><br><span class="line"><span class="punctuation">&#123;</span></span><br><span class="line">     <span class="attr">&quot;doc&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line">       <span class="attr">&quot;author&quot;</span><span class="punctuation">:</span> <span class="string">&quot;Albert Paro&quot;</span><span class="punctuation">,</span></span><br><span class="line">       <span class="attr">&quot;title&quot;</span><span class="punctuation">:</span> <span class="string">&quot;Elasticsearch 5.0 Cookbook&quot;</span><span class="punctuation">,</span></span><br><span class="line">       <span class="attr">&quot;description&quot;</span><span class="punctuation">:</span> <span class="string">&quot;Elasticsearch 5.0 Cookbook Third Edition&quot;</span><span class="punctuation">,</span></span><br><span class="line">       <span class="attr">&quot;price&quot;</span><span class="punctuation">:</span> <span class="string">&quot;54.99&quot;</span></span><br><span class="line">      <span class="punctuation">&#125;</span><span class="punctuation">,</span></span><br><span class="line">     <span class="attr">&quot;doc_as_upsert&quot;</span><span class="punctuation">:</span> <span class="literal"><span class="keyword">true</span></span></span><br><span class="line"><span class="punctuation">&#125;</span></span><br></pre></td></tr></table></figure>





<h4 id="检查一个文档是否存在"><a href="#检查一个文档是否存在" class="headerlink" title="检查一个文档是否存在"></a>检查一个文档是否存在</h4><figure class="highlight json"><table><tr><td class="code"><pre><span class="line">HEAD twitter/_doc/<span class="number">1</span></span><br></pre></td></tr></table></figure>

<p>如果存在</p>
<figure class="highlight json"><table><tr><td class="code"><pre><span class="line"><span class="number">200</span> - OK</span><br></pre></td></tr></table></figure>

<p>如果不存在</p>
<figure class="highlight json"><table><tr><td class="code"><pre><span class="line"><span class="number">404</span> - Not Found</span><br></pre></td></tr></table></figure>



<h4 id="删除一个文档"><a href="#删除一个文档" class="headerlink" title="删除一个文档"></a>删除一个文档</h4><figure class="highlight json"><table><tr><td class="code"><pre><span class="line">DELETE /&lt;index&gt;/_doc/&lt;_id&gt;</span><br></pre></td></tr></table></figure>

<figure class="highlight json"><table><tr><td class="code"><pre><span class="line">DELETE twitter/_doc/<span class="number">1</span></span><br></pre></td></tr></table></figure>



<h4 id="检查一个索引是否存在"><a href="#检查一个索引是否存在" class="headerlink" title="检查一个索引是否存在"></a>检查一个索引是否存在</h4><figure class="highlight json"><table><tr><td class="code"><pre><span class="line">HEAD twitter</span><br></pre></td></tr></table></figure>



<h4 id="删除一个索引"><a href="#删除一个索引" class="headerlink" title="删除一个索引"></a>删除一个索引</h4><figure class="highlight json"><table><tr><td class="code"><pre><span class="line">DELETE twitter</span><br></pre></td></tr></table></figure>



<h4 id="批处理命令"><a href="#批处理命令" class="headerlink" title="批处理命令"></a>批处理命令</h4><p><strong>_bulk</strong> 命令 ,批量 API。</p>
<p>在单个 API 调用中执行多个索引或删除操作。这减少了开销并且可以大大提高索引速度。</p>
<figure class="highlight json"><table><tr><td class="code"><pre><span class="line">POST /_bulk?pretty</span><br><span class="line"><span class="punctuation">&#123;</span> <span class="attr">&quot;index&quot;</span> <span class="punctuation">:</span> <span class="punctuation">&#123;</span> <span class="attr">&quot;_index&quot;</span> <span class="punctuation">:</span> <span class="string">&quot;test&quot;</span><span class="punctuation">,</span> <span class="attr">&quot;_id&quot;</span> <span class="punctuation">:</span> <span class="string">&quot;1&quot;</span> <span class="punctuation">&#125;</span> <span class="punctuation">&#125;</span></span><br><span class="line"><span class="punctuation">&#123;</span> <span class="attr">&quot;field1&quot;</span> <span class="punctuation">:</span> <span class="string">&quot;value1&quot;</span> <span class="punctuation">&#125;</span></span><br><span class="line"><span class="punctuation">&#123;</span> <span class="attr">&quot;delete&quot;</span> <span class="punctuation">:</span> <span class="punctuation">&#123;</span> <span class="attr">&quot;_index&quot;</span> <span class="punctuation">:</span> <span class="string">&quot;test&quot;</span><span class="punctuation">,</span> <span class="attr">&quot;_id&quot;</span> <span class="punctuation">:</span> <span class="string">&quot;2&quot;</span> <span class="punctuation">&#125;</span> <span class="punctuation">&#125;</span></span><br><span class="line"><span class="punctuation">&#123;</span> <span class="attr">&quot;create&quot;</span> <span class="punctuation">:</span> <span class="punctuation">&#123;</span> <span class="attr">&quot;_index&quot;</span> <span class="punctuation">:</span> <span class="string">&quot;test&quot;</span><span class="punctuation">,</span> <span class="attr">&quot;_id&quot;</span> <span class="punctuation">:</span> <span class="string">&quot;3&quot;</span> <span class="punctuation">&#125;</span> <span class="punctuation">&#125;</span></span><br><span class="line"><span class="punctuation">&#123;</span> <span class="attr">&quot;field1&quot;</span> <span class="punctuation">:</span> <span class="string">&quot;value3&quot;</span> <span class="punctuation">&#125;</span></span><br><span class="line"><span class="punctuation">&#123;</span> <span class="attr">&quot;update&quot;</span> <span class="punctuation">:</span> <span class="punctuation">&#123;</span><span class="attr">&quot;_id&quot;</span> <span class="punctuation">:</span> <span class="string">&quot;1&quot;</span><span class="punctuation">,</span> <span class="attr">&quot;_index&quot;</span> <span class="punctuation">:</span> <span class="string">&quot;test&quot;</span><span class="punctuation">&#125;</span> <span class="punctuation">&#125;</span></span><br><span class="line"><span class="punctuation">&#123;</span> <span class="attr">&quot;doc&quot;</span> <span class="punctuation">:</span> <span class="punctuation">&#123;</span><span class="attr">&quot;field2&quot;</span> <span class="punctuation">:</span> <span class="string">&quot;value2&quot;</span><span class="punctuation">&#125;</span> <span class="punctuation">&#125;</span></span><br></pre></td></tr></table></figure>



<h3 id="结语"><a href="#结语" class="headerlink" title="结语"></a>结语</h3><p>Elasticsearch 最重要的功能就是查询，等有机会好好总结一下有关于 Elasticsearch 的各种查询！</p>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="https://curry3035.gitee.io">PaulGeorge</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://curry3035.gitee.io/posts/27951/">https://curry3035.gitee.io/posts/27951/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://curry3035.gitee.io" target="_blank">Celts</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/%E8%BF%9B%E9%98%B6/">进阶</a><a class="post-meta__tags" href="/tags/es/">es</a></div><div class="post_share"><div class="social-share" data-image="/img/avatar.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/posts/30553/" title="hexo 博客总结"><div class="cover" style="background: var(--default-bg-color)"></div><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">hexo 博客总结</div></div></a></div><div class="next-post pull-right"><a href="/posts/39089/" title="实践一下--SpringBoot多模块项目"><div class="cover" style="background: var(--default-bg-color)"></div><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">实践一下--SpringBoot多模块项目</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><div><a href="/posts/55119/" title="每日一面--Files工具类"><div class="cover" style="background: var(--default-bg-color)"></div><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-01-01</div><div class="title">每日一面--Files工具类</div></div></a></div><div><a href="/posts/34600/" title="面试一下--JUC入门"><div class="cover" style="background: var(--default-bg-color)"></div><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-09-10</div><div class="title">面试一下--JUC入门</div></div></a></div><div><a href="/posts/11315/" title="实践一下--Spring Security"><div class="cover" style="background: var(--default-bg-color)"></div><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-06-01</div><div class="title">实践一下--Spring Security</div></div></a></div><div><a href="/posts/40042/" title="每日一面--反射"><div class="cover" style="background: var(--default-bg-color)"></div><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-05-01</div><div class="title">每日一面--反射</div></div></a></div><div><a href="/posts/56511/" title="实践一下--MySQL 优化"><div class="cover" style="background: var(--default-bg-color)"></div><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-01-04</div><div class="title">实践一下--MySQL 优化</div></div></a></div><div><a href="/posts/39089/" title="实践一下--SpringBoot多模块项目"><div class="cover" style="background: var(--default-bg-color)"></div><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-09-20</div><div class="title">实践一下--SpringBoot多模块项目</div></div></a></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="/img/avatar.jpg" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">PaulGeorge</div><div class="author-info__description">很多事情就像是旅行一样，当你决定要出发的时候，最困难的那部分其实就已经完成了</div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">97</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">64</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">25</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/PaulGeorge123"><i class="fab fa-github"></i><span>GitHub URL</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/PaulGeorge123" target="_blank" title="Github"><i class="fab fa-github"></i></a></div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content is-expand"><ol class="toc"><li class="toc-item toc-level-3"><a class="toc-link" href="#ElasticSearch-%E7%9A%84%E5%9F%BA%E6%9C%AC%E6%A6%82%E5%BF%B5"><span class="toc-number">1.</span> <span class="toc-text">ElasticSearch 的基本概念</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%A6%82%E5%BF%B5%E5%8C%85%E6%8B%AC"><span class="toc-number">1.1.</span> <span class="toc-text">概念包括</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E9%9B%86%E7%BE%A4%EF%BC%88cluster%EF%BC%89"><span class="toc-number">1.2.</span> <span class="toc-text">集群（cluster）</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%AE%9E%E4%BE%8B%EF%BC%88node%EF%BC%89"><span class="toc-number">1.3.</span> <span class="toc-text">实例（node）</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E7%B4%A2%E5%BC%95%EF%BC%88index%EF%BC%89"><span class="toc-number">1.4.</span> <span class="toc-text">索引（index）</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%96%87%E6%A1%A3%EF%BC%88document%EF%BC%89"><span class="toc-number">1.5.</span> <span class="toc-text">文档（document）</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%88%86%E7%89%87%EF%BC%88shard%EF%BC%89"><span class="toc-number">1.6.</span> <span class="toc-text">分片（shard）</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%89%AF%E6%9C%AC%EF%BC%88replica%EF%BC%89"><span class="toc-number">1.7.</span> <span class="toc-text">副本（replica）</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%98%A0%E5%B0%84%EF%BC%88mapping%EF%BC%89"><span class="toc-number">1.8.</span> <span class="toc-text">映射（mapping）</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%96%87%E6%A1%A3%E7%B1%BB%E5%9E%8B%EF%BC%88type%EF%BC%89"><span class="toc-number">1.9.</span> <span class="toc-text">文档类型（type）</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#RESTful-API"><span class="toc-number">1.10.</span> <span class="toc-text">RESTful API</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%95%B0%E6%8D%AE%E6%A0%BC%E5%BC%8F"><span class="toc-number">1.11.</span> <span class="toc-text">数据格式</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#ElasticSearch-%E6%93%8D%E4%BD%9C"><span class="toc-number">2.</span> <span class="toc-text">ElasticSearch 操作</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#ElasticSearch-API"><span class="toc-number">2.1.</span> <span class="toc-text">ElasticSearch API</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%9F%A5%E7%9C%8B%E6%89%80%E6%9C%89%E7%B4%A2%E5%BC%95"><span class="toc-number">2.2.</span> <span class="toc-text">查看所有索引</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%88%9B%E5%BB%BA%E4%B8%80%E4%B8%AA%E7%B4%A2%E5%BC%95%E5%8F%8A%E6%96%87%E6%A1%A3"><span class="toc-number">2.3.</span> <span class="toc-text">创建一个索引及文档</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E8%87%AA%E5%8A%A8-ID-%E7%94%9F%E6%88%90"><span class="toc-number">2.4.</span> <span class="toc-text">自动 ID 生成</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E4%BF%AE%E6%94%B9%E4%B8%80%E4%B8%AA%E6%96%87%E6%A1%A3"><span class="toc-number">2.5.</span> <span class="toc-text">修改一个文档</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#UPSERT-%E4%B8%80%E4%B8%AA%E6%96%87%E6%A1%A3"><span class="toc-number">2.6.</span> <span class="toc-text">UPSERT 一个文档</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%A3%80%E6%9F%A5%E4%B8%80%E4%B8%AA%E6%96%87%E6%A1%A3%E6%98%AF%E5%90%A6%E5%AD%98%E5%9C%A8"><span class="toc-number">2.7.</span> <span class="toc-text">检查一个文档是否存在</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%88%A0%E9%99%A4%E4%B8%80%E4%B8%AA%E6%96%87%E6%A1%A3"><span class="toc-number">2.8.</span> <span class="toc-text">删除一个文档</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%A3%80%E6%9F%A5%E4%B8%80%E4%B8%AA%E7%B4%A2%E5%BC%95%E6%98%AF%E5%90%A6%E5%AD%98%E5%9C%A8"><span class="toc-number">2.9.</span> <span class="toc-text">检查一个索引是否存在</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%88%A0%E9%99%A4%E4%B8%80%E4%B8%AA%E7%B4%A2%E5%BC%95"><span class="toc-number">2.10.</span> <span class="toc-text">删除一个索引</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%89%B9%E5%A4%84%E7%90%86%E5%91%BD%E4%BB%A4"><span class="toc-number">2.11.</span> <span class="toc-text">批处理命令</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%BB%93%E8%AF%AD"><span class="toc-number">3.</span> <span class="toc-text">结语</span></a></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/posts/47231/" title="POI读取Excel问题">POI读取Excel问题</a><time datetime="2023-04-11T01:00:00.000Z" title="发表于 2023-04-11 09:00:00">2023-04-11</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/posts/8422/" title="Excel大文件的上传">Excel大文件的上传</a><time datetime="2023-04-10T01:00:00.000Z" title="发表于 2023-04-10 09:00:00">2023-04-10</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/posts/55119/" title="每日一面--Files工具类">每日一面--Files工具类</a><time datetime="2023-01-01T01:00:00.000Z" title="发表于 2023-01-01 09:00:00">2023-01-01</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/posts/34600/" title="面试一下--JUC入门">面试一下--JUC入门</a><time datetime="2022-09-10T01:00:00.000Z" title="发表于 2022-09-10 09:00:00">2022-09-10</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/posts/16284/" title="每日一面--字符流和字节流">每日一面--字符流和字节流</a><time datetime="2022-07-01T01:00:00.000Z" title="发表于 2022-07-01 09:00:00">2022-07-01</time></div></div></div></div></div></div></main><footer id="footer" style="background-image: url('https://gcore.jsdelivr.net/gh/PaulGeorge123/cloudimg@img/mig2023/background05.jpg')"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2023 By PaulGeorge</div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.min.js"></script><script src="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.js"></script><div class="js-pjax"></div><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div id="local-search-results"></div></div></div><div id="search-mask"></div><script src="/js/search/local-search.js"></script></div></body></html>